
<?php
//模块插件类
//对外接口函数类，其他插件可通过“$this->plugin('jy_faceocr')->方法名” 来调用本类的方法
defined('BY_JYA') or exit('error');
class func_jy_faceocr extends plugin{
	public function facecheck($realName,$idCardNum,$host,$path){
		$setting=$this->get_setting();
		$access_token=$setting['access_token'];

		$idCardNum=$idCardNum;//身份证号码
		$realName=$realName;//姓名
		$host = $host;
		$path = $path;
		$url = $host . $path;
		if($fp = fopen($url, "rb", 0)) { 
			$binary = fread($fp, filesize($url)); // 文件读取
			fclose($fp); 
			$base64 = base64_encode($binary); // 转码
		}
		$image=$base64;//头像base64
		$param=array('idCardNum'=>$idCardNum,'image'=>$image,'realName'=>iconv("GB2312","UTF-8//IGNORE",$realName));
		$headers = array();
		//你自己的AppCode
		$appcode=$setting['appcode'];
		array_push($headers, "Authorization:APPCODE " . $appcode);
		array_push($headers, "Content-Type".":"."application/x-www-form-urlencoded; charset=UTF-8");



		$oCurl = curl_init();
		if (stripos($url, "https://") !== FALSE) {
			curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER, FALSE);
			curl_setopt($oCurl, CURLOPT_SSL_VERIFYHOST, false);
		}

		$strPOST = http_build_query($param);


		curl_setopt($oCurl, CURLOPT_URL, $url);
		curl_setopt($oCurl, CURLOPT_POST, true);
		curl_setopt($oCurl, CURLOPT_POSTFIELDS, $strPOST);

		curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1);
		if ($headers)
			curl_setopt($oCurl, CURLOPT_HTTPHEADER, $headers);
		curl_setopt($oCurl, CURLOPT_TIMEOUT, 30);
		$sContent = curl_exec($oCurl);
		$aStatus = curl_getinfo($oCurl);
		curl_close($oCurl);
		if (intval($aStatus["http_code"]) == 200) {
			exi($sContent,'error');
		} else {
			return $aStatus["http_code"];
		}     
	}
}
?>
